package com.astrob.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.astrob.nhcmap.R;

import java.util.List;

public class ListA2VAdapter extends BaseAdapter {
	static class ViewHolder {
		TextView text;
		TextView text2;
	}

	protected Context mContext;
	protected List<String> mListText;
	protected List<String> mListText2;

	public ListA2VAdapter(Context context, final List<String> text, final List<String> text2) {
		mContext = context;
		mListText = text;
		mListText2 = text2;
	}

	@Override
	public int getCount() {
		if (mListText != null) {
			return mListText.size();
		}
		return 0;
	}

	@Override
	public Object getItem(int position) {
		if (mListText != null) {
			return mListText.get(position);
		}
		return null;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	private int dip2px(float dpValue) {
		final float scale = mContext.getResources().getDisplayMetrics().density;
		return (int) (dpValue * scale + 0.5f);
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (null == convertView) {
			convertView = LinearLayout.inflate(mContext, R.layout.lista2v, null);
			convertView.setLayoutParams(new android.widget.AbsListView.LayoutParams(-1, dip2px(60)));
			holder = new ViewHolder();
			holder.text = (TextView) convertView.findViewById(R.id.listAText1);
			holder.text2 = (TextView) convertView.findViewById(R.id.listAText2);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		if (mListText2 != null) {
			String t = mListText2.get(position);
			if(t == null || t.length() == 0){
				holder.text2.setVisibility(View.GONE);
			}
			else {
				holder.text2.setVisibility(View.VISIBLE);
				holder.text2.setText(t);
			}
		}
		if (mListText != null) {
			holder.text.setText(mListText.get(position));
		}
		return convertView;
	}

}
